package com.sam.im.heiqun.uis.activities;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.sam.im.heiqun.R;
import com.sam.im.heiqun.app.App;
import com.sam.im.heiqun.entities.GetmoneyEntivity;
import com.sam.im.heiqun.entities.ImMessage;
import com.sam.im.heiqun.entities.PayTransferEntivity;
import com.sam.im.heiqun.nets.PGService;
import com.sam.im.heiqun.utils.ToolsUtils;
import com.yuyh.library.nets.callbacks.AbsAPICallback;
import com.yuyh.library.nets.exceptions.ApiException;
import com.yuyh.library.uis.activitys.BaseSwipeBackActivity;
import com.yuyh.library.utils.GlideUtils;

import butterknife.BindView;
import butterknife.OnClick;
import com.sam.im.heiqun.utils.StringUtils;

/**
 * Created by wangguodong on 2017/8/18.
 */

public class PayInPutMoneyActivity extends BaseSwipeBackActivity {


    @BindView(R.id.pre_v_back)
    ImageView preVBack;
    @BindView(R.id.img_icon)
    ImageView imgIcon;
    @BindView(R.id.tvdiscrible)
    TextView username;
    @BindView(R.id.edit_money)
    EditText edit_money;
    @BindView(R.id.bt_sure)
    Button bt_sure;

    private ImMessage topay;
    String money ;
    String paymoney;
    private GetmoneyEntivity getmoneyEntivity;
    private PayTransferEntivity payTransferEntivity;

    @Override
    protected String getTitleText() {
        return getResources().getString(R.string.input_money);
    }

    @Override
    protected void initViews(Bundle savedInstanceState) {
        money = getIntent().getStringExtra("money");
        paymoney = getIntent().getStringExtra("paymoney");
        topay = (ImMessage) getIntent().getSerializableExtra("topay");

        if (money != null && !StringUtils.isEmpty(money)) {
            try {
                getmoneyEntivity = new Gson().fromJson(money, GetmoneyEntivity.class);
                String receiptHeadUrl = getmoneyEntivity.getReceiptHeadUrl();
                String receiptName = getmoneyEntivity.getReceiptName();
                username.setText(receiptName);
                GlideUtils.loadImage(this, receiptHeadUrl, imgIcon);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (topay != null) {
            String receiptName = topay.getFromname();
            username.setText(receiptName);
            GlideUtils.loadImage(this, topay.getImageIconUrl(), imgIcon);
        }
        if (paymoney != null && !StringUtils.isEmpty(paymoney)) {
            try {
                payTransferEntivity = new Gson().fromJson(paymoney, PayTransferEntivity.class);
                String paymentName = payTransferEntivity.getPaymentName();
                String paymentHeadUrl = payTransferEntivity.getPaymentHeadUrl();
                GlideUtils.loadImage(this, paymentHeadUrl, imgIcon);
                username.setText(paymentName);
            } catch (Exception e) {

            }
        }

    }

    @Override
    public int getContentViewId() {
        return R.layout.activity_pay_input;
    }


    @OnClick({R.id.pre_v_back, R.id.bt_sure})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.pre_v_back:
                finish();
                break;
            case R.id.bt_sure://确认付款

                String moneyg = edit_money.getText().toString();
                try {
                    if (null!=moneyg && !"".equals(moneyg) && Integer.parseInt(moneyg) > 0){
                        Intent intent = new Intent();
                        intent.putExtra("editmoney",moneyg);
                        setResult(10,intent);
                    }
                }catch (Exception e){
                    e.printStackTrace();
                }
                finish();

                break;
        }
    }

}
